package com.hsgene.product.controller;

import com.hsgene.common.ClientType;
import com.hsgene.common.util.result.ApiResult;
import com.hsgene.common.util.support.LimitHelper;
import com.hsgene.common.util.support.OrderHelper;
import com.hsgene.common.util.support.Pagination;
import com.hsgene.product.condition.PackageCondition;
import com.hsgene.product.condition.ReportTemplateCondition;
import com.hsgene.product.domain.GeneticTestingReportTemplate;
import com.hsgene.product.dto.GeneticTestingReportTemplateDto;
import com.hsgene.product.service.ReportTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: //TODO
 * @ProjectName: hdas-geneshop-server
 * @Package: com.hsgene.product.controller
 * @Author: FX
 * @CreateDate: 2018/11/5 11:28
 * @Version: 1.0
 * Copyright: Copyright (c) 2018
 */
@RestController
@RequestMapping("/v1.0/genetic/testing/report/template")
public class ReportTemplateController {

    @Autowired
    ReportTemplateService reportTemplateService;
    /**
     *t添加
     * @author FX
     * @date 2018/11/5 11:38
     * @param geneticTestingReportTemplate
     * @return
     */
    @PostMapping
    public ApiResult addReportTemplate(@RequestBody GeneticTestingReportTemplate geneticTestingReportTemplate){
        return reportTemplateService.addReportTemplate(geneticTestingReportTemplate);
    }
    /**
     *更新模板
     * @author FX
     * @date 2018/11/5 11:49
     * @param geneticTestingReportTemplate
     * @return
     */
    @PutMapping
    public ApiResult updateReportTemplate(@RequestBody GeneticTestingReportTemplate geneticTestingReportTemplate){
        return reportTemplateService.updateReportTemplate(geneticTestingReportTemplate);
    }
    /**
     *
     * @author FX
     * @date 2018/11/5 13:32
     * @param page
     * @param size
     * @param condition
     * @return
     */
    @GetMapping
    public ApiResult getList(Integer page, Integer size, ReportTemplateCondition condition){
        if(ClientType.PEANUT.getCode().equals(condition.getPlatform())){
            condition.setOrderHelper(OrderHelper.create("a.update_date_time", false));
            return reportTemplateService.getListPean(condition);
        }else{
            condition.setLimitHelper(LimitHelper.create(page, size, true));
            condition.setOrderHelper(OrderHelper.create("a.update_date_time", false));
            return  reportTemplateService.getList(condition);
        }
    }
    /**
     *删除模板
     * @author FX
     * @date 2018/11/5 16:18
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public ApiResult deleteTeplete(@PathVariable("id") String id){
        return reportTemplateService.deleteTeplete(id);
    }
    /**
     *删除模板批量
     * @author FX
     * @date 2018/11/5 16:18
     * @param id
     * @return
     */
    @DeleteMapping
    public ApiResult deleteTepleteMore(@RequestBody List<GeneticTestingReportTemplate> testingReportTemplates){
        return reportTemplateService.deleteTepleteMore(testingReportTemplates);
    }


    /**
     *
     * @author FX
     * @date 2018/11/5 16:46
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public ApiResult<GeneticTestingReportTemplateDto> getById(@PathVariable("id") String id){
        return reportTemplateService.getById(id);
    }
}
